package com.wbpay.sdk.dlg;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wbpay.sdk.framework.IUserFunction;
import com.wbpay.sdk.params.User;
import com.wbpay.sdk.utils.Utils;

/**
 * Created by ck01- on 2017/7/6.
 */

public class UserCenterDialog extends Dialog {

    private IUserFunction mUserFunction;
    private TextView tv_user_center_close;
    private TextView tv_username;
    private ImageView iv_exchange;
    private String loginUserName;

    public UserCenterDialog(Context context, IUserFunction f) {
        super(context, android.R.style.Theme_DeviceDefault_NoActionBar);
        mUserFunction = f;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(Utils.getLayoutId(getContext(), "jy_dialog_user_center"));
        initView();
        initData();
    }

    private void initView() {
        tv_user_center_close = (TextView) findViewById(Utils.getId(getContext(),
                "tv_user_center_close"));
        tv_username = (TextView) findViewById(Utils.getId(getContext(),
                "tv_username"));
        iv_exchange = (ImageView) findViewById(Utils.getId(getContext(),
                "iv_exchange"));
        tv_user_center_close.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        iv_exchange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                mUserFunction.switchUser();
            }
        });
    }

    private void initData() {
        if (mUserFunction != null) {
            User user = mUserFunction.loadLoginUser();
            String username = user == null ? "" : user.getUsername();
            username = username == null ? "" : username;
            tv_username.setText("久游通行证:" + username);
        }

    }
}
